/**
 *
 * 2007-11-2 下午08:07:32
 * @author xuhuan
 */

package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnInformationNode;

public class InformationNodeLoader extends NodeLoader {
	
	protected SaturnInformationNode createInformationNode(){
		return new SaturnInformationNode();
	}

	public List<Shape> loadNodes(Element root) {

		NodeList informationNodes = root
				.getElementsByTagName(SaturnInformationNode.KEY_NODE_INFORMATION);

		List<Shape> shapes = new ArrayList<Shape>(informationNodes.getLength());

		for (int i = 0; i < informationNodes.getLength(); ++i) {
			SaturnInformationNode saturninformationNode = createInformationNode();

			Node informationNode = informationNodes.item(i);
			String shapeId = super.getNodeAttributeValue(informationNode,
					Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(informationNode,
					Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			String key = super.getNodeElementValue(informationNode,
					SaturnInformationNode.SHOW_INFORMATION_NODE_KEY);
			String name = super.getNodeElementValue(informationNode,
					SaturnInformationNode.SHOW_INFORMATION_NODE_NAME);
			String description = super.getNodeElementValue(informationNode,
					SaturnInformationNode.SHOW_INFORMATION_NODE_DESCRITPION);
//			String loadstart = super.getNodeElementValue(informationNode,
//					SaturnInformationNode.SHOW_INFORMATION_NODE_LOADSTART);
//			String symbolicName = super.getNodeElementValue(informationNode,
//					SaturnInformationNode.SHOW_INFORMATION_NODE_SYMBOLICNAME);
			Point location = super.getLocation(informationNode);
			Dimension size = new Dimension(50, 70);

			saturninformationNode.setNode(informationNode);
			saturninformationNode.setId(shapeId);
			saturninformationNode.setLocation(location);
			saturninformationNode.setKey(key);
			saturninformationNode.setName(name);
			saturninformationNode.setNextId(nextId);
			saturninformationNode.setDescription(description);
//			saturninformationNode.setSelection(loadstart);
//			saturninformationNode.setSymbolicName(symbolicName);
			saturninformationNode.setSize(size);

			shapes.add(saturninformationNode);
		}

		return shapes;
	}
}
